<template>
  <div>
    <h2>随机点名</h2>
    <div class="box">
      <span>名字是:</span>
      <div class="qs">这里显示姓名 {{ names }}</div>
    </div>
    <div class="btns">
      <button class="start" @click="getM">开始</button>
      <button class="end" @click="caret">结束</button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      names: '',
      arrx: ['张', '李', '王', '刘', '陈', '周', '胡', '万', '邓'],
      arrm: ['敏', '丽', '勇', '磊', '娟', '明', '涛', '杰', '桂'],
      mathm1: '',
      mathm2: '',
      mathx: '',
      sum: 2,
      timer: ''
    }
  },
  methods: {
    getM() {
      clearInterval(this.timer)
      this.timer = setInterval(() => {
        function math(m, n) {
          return parseInt(Math.random() * (m - n + 1) + n)
        }
        this.mathm1 = math(8, 0)
        this.mathm2 = math(8, 0)
        this.mathm3 = math(8, 0)
        this.mathx = math(8, 0)
        this.sum = math(3, 2)
        if (this.sum == 2) {
          this.names = this.arrx[this.mathx] + this.arrm[this.mathm1]
        } else {
          this.names = this.arrx[this.mathx] + this.arrm[this.mathm1] + this.arrm[this.mathm2]
        }
      }, 100)
    },
    caret() {
      clearInterval(this.timer)
    }
  }
}
</script>

<style>
* {
  margin: 0;
  padding: 0;
}

h2 {
  text-align: center;
}

.box {
  width: 600px;
  margin: 50px auto;
  display: flex;
  font-size: 25px;
  line-height: 40px;
}

.qs {
  width: 450px;
  height: 40px;
  color: red;
}

.btns {
  text-align: center;
}

.btns button {
  width: 120px;
  height: 35px;
  margin: 0 50px;
}
</style>
